

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>scitools.Lumpy &mdash; SciTools 0.8.3 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.8.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="SciTools 0.8.3 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SciTools 0.8.3 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for scitools.Lumpy</h1><div class="highlight"><pre>
<span class="c">#!/usr/bin/python</span>
<span class="c"># some adjustments to the original Lumpy.py code (marked &quot;hpl code&quot; below)</span>

<span class="sd">&quot;&quot;&quot;UML diagrams for Python</span>

<span class="sd">Lumpy generates UML diagrams (currently object and class diagrams)</span>
<span class="sd">from a running Python program. It is similar to a graphical debugger</span>
<span class="sd">in the sense that it generates a visualization of the state of a</span>
<span class="sd">running program, but it is different from a debugger in the sense that</span>
<span class="sd">it tries to generate high-level visualizations that are compliant (at</span>
<span class="sd">least in spirit) with standard UML.</span>

<span class="sd">There are three target audiences for this module: teachers, students</span>
<span class="sd">and software engineers. Teachers can use Lumpy to generate figures</span>
<span class="sd">that demonstrate a model of the execution of a Python</span>
<span class="sd">program. Students can use Lumpy to explore the behavior of the Python</span>
<span class="sd">interpreter. Software engineers can use Lumpy to extract the structure</span>
<span class="sd">of existing programs by diagramming the relationships among the</span>
<span class="sd">classes, including classes defined in libraries and the Python</span>
<span class="sd">interpreter.</span>


<span class="sd">  Copyright 2005 Allen B. Downey</span>

<span class="sd">    This file contains wrapper classes I use with tkinter.  It is</span>
<span class="sd">    mostly for my own use; I don&#39;t support it, and it is not very</span>
<span class="sd">    well documented.</span>

<span class="sd">    This program is free software; you can redistribute it and/or modify</span>
<span class="sd">    it under the terms of the GNU General Public License as published by</span>
<span class="sd">    the Free Software Foundation; either version 2 of the License, or</span>
<span class="sd">    (at your option) any later version.</span>

<span class="sd">    This program is distributed in the hope that it will be useful,</span>
<span class="sd">    but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="sd">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="sd">    GNU General Public License for more details.</span>

<span class="sd">    You should have received a copy of the GNU General Public License</span>
<span class="sd">    along with this program; if not, see</span>
<span class="sd">    http://www.gnu.org/licenses/gpl.html or write to the Free Software</span>
<span class="sd">    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA</span>
<span class="sd">    02110-1301 USA</span>
<span class="sd">    </span>
<span class="sd">&quot;&quot;&quot;</span>



<span class="kn">import</span> <span class="nn">inspect</span><span class="o">,</span> <span class="nn">traceback</span>
<span class="kn">from</span> <span class="nn">_Gui</span> <span class="kn">import</span> <span class="o">*</span>

<span class="c"># get the version of Python</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">version</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="s">&#39;2&#39;</span><span class="p">:</span>
    <span class="k">print</span> <span class="s">&#39;You must have at least Python version 2.0 to run Lumpy.&#39;</span>
    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">()</span>

<span class="n">minor</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">if</span> <span class="n">minor</span> <span class="o">&lt;</span> <span class="mi">4</span><span class="p">:</span>
    <span class="c"># need to find a substitute implementation of set</span>
    <span class="k">pass</span>
        

<span class="c"># most text uses the font specified below; some labels</span>
<span class="c"># in object diagrams use smallfont.  Lumpy uses the size</span>
<span class="c"># of the fonts to define a length unit, so</span>
<span class="c"># changing the font sizes will cause the whole diagram to</span>
<span class="c"># scale up or down.</span>
<span class="n">font</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;Helvetica&quot;</span><span class="p">,</span> <span class="mi">12</span><span class="p">)</span>
<span class="n">smallfont</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;Helvetica&quot;</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>


<div class="viewcode-block" id="DiagCanvas"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.DiagCanvas">[docs]</a><span class="k">class</span> <span class="nc">DiagCanvas</span><span class="p">(</span><span class="n">GuiCanvas</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;a Canvas for displaying Diagrams&quot;&quot;&quot;</span>
    
<div class="viewcode-block" id="DiagCanvas.box"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.DiagCanvas.box">[docs]</a>    <span class="k">def</span> <span class="nf">box</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">box</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mf">0.3</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw a rectangle with the given bounding box, expanded</span>
<span class="sd">        by padx and pady.  box can be a Bbox object or a list of</span>
<span class="sd">        two coordinate pairs.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c"># underride sets default values only if the called hasn&#39;t</span>
        <span class="n">underride</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="n">outline</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">)</span>
        <span class="n">box</span><span class="o">.</span><span class="n">left</span> <span class="o">-=</span> <span class="n">padx</span>
        <span class="n">box</span><span class="o">.</span><span class="n">top</span> <span class="o">-=</span> <span class="n">pady</span>
        <span class="n">box</span><span class="o">.</span><span class="n">right</span> <span class="o">+=</span> <span class="n">padx</span>
        <span class="n">box</span><span class="o">.</span><span class="n">bottom</span> <span class="o">+=</span> <span class="n">pady</span>
        <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rectangle</span><span class="p">(</span><span class="n">box</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">item</span>
</div>
<div class="viewcode-block" id="DiagCanvas.arrow"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.DiagCanvas.arrow">[docs]</a>    <span class="k">def</span> <span class="nf">arrow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw an arrow: start and end can be a Pos object or</span>
<span class="sd">        a list of two coordinates</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">line</span><span class="p">([</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">],</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DiagCanvas.str"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.DiagCanvas.str">[docs]</a>    <span class="k">def</span> <span class="nf">str</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="n">dx</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dy</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw the given text at the given position, with an offset</span>
<span class="sd">        specified by dx and dy</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">underride</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span> <span class="n">font</span><span class="o">=</span><span class="n">font</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="n">W</span><span class="p">)</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">pos</span>
        <span class="n">x</span> <span class="o">+=</span> <span class="n">dx</span>
        <span class="n">y</span> <span class="o">+=</span> <span class="n">dy</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="n">text</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="DiagCanvas.dot"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.DiagCanvas.dot">[docs]</a>    <span class="k">def</span> <span class="nf">dot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">r</span><span class="o">=</span><span class="mf">0.2</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw a dot at the given position with radius r&quot;&quot;&quot;</span>
        <span class="n">underride</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;white&#39;</span><span class="p">,</span> <span class="n">outline</span><span class="o">=</span><span class="s">&#39;orange&#39;</span><span class="p">)</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">pos</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">circle</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="DiagCanvas.measure"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.DiagCanvas.measure">[docs]</a>    <span class="k">def</span> <span class="nf">measure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;find the bounding box of the list of words by</span>
<span class="sd">        drawing them, measuring them, and then deleting them</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">pos</span> <span class="o">=</span> <span class="n">Pos</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">tags</span> <span class="o">=</span> <span class="s">&#39;temp&#39;</span>
        <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">t</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">str</span><span class="p">(</span><span class="n">pos</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span>
            <span class="n">pos</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">bbox</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="n">tags</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">tags</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">bbox</span>
    
</div></div>
<span class="n">nextid</span> <span class="o">=</span> <span class="mi">0</span>
<div class="viewcode-block" id="make_tags"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.make_tags">[docs]</a><span class="k">def</span> <span class="nf">make_tags</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s">&#39;Tag&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;return a tuple with a single element: a tag string with</span>
<span class="sd">    with the given prefix and a unique id as a suffix</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">global</span> <span class="n">nextid</span>
    <span class="n">nextid</span> <span class="o">+=</span> <span class="mi">1</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="n">nextid</span><span class="p">)</span>
    <span class="k">return</span> <span class="nb">id</span><span class="p">,</span>

</div>
<div class="viewcode-block" id="Thing"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing">[docs]</a><span class="k">class</span> <span class="nc">Thing</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the parent class for objects that have a graphical</span>
<span class="sd">    representation.  Each Thing object corresponds to an item</span>
<span class="sd">    or set of items in a diagram.  A Thing can only be drawn in</span>
<span class="sd">    one Diagram at a time.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">things_created</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">things_drawn</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">def</span> <span class="nf">__new__</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;override __new__ so we can count the number of Things&quot;&quot;&quot;</span>
        <span class="n">Thing</span><span class="o">.</span><span class="n">things_created</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="nb">object</span><span class="o">.</span><span class="n">__new__</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">)</span>
    
<div class="viewcode-block" id="Thing.bbox"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.bbox">[docs]</a>    <span class="k">def</span> <span class="nf">bbox</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the bounding box of this object if it is drawn</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tags</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="Thing.set_offset"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.set_offset">[docs]</a>    <span class="k">def</span> <span class="nf">set_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;the offset attribute keeps track of the offset between</span>
<span class="sd">        the bounding box of the Thing and its nominal position, so</span>
<span class="sd">        that if the Thing is moved later, we can compute its new</span>
<span class="sd">        nominal position.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">offset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span><span class="o">.</span><span class="n">offset</span><span class="p">(</span><span class="n">pos</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Thing.pos"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.pos">[docs]</a>    <span class="k">def</span> <span class="nf">pos</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Compute the nominal position of a Thing by getting the</span>
<span class="sd">        current bounding box and adding the offset.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span><span class="o">.</span><span class="n">pos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">offset</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Thing.isdrawn"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.isdrawn">[docs]</a>    <span class="k">def</span> <span class="nf">isdrawn</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return True if the object has been drawn&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&#39;drawn&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Thing.draw"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="sd">&quot;&quot;&quot;draw this Thing at the given position on the given</span>
<span class="sd">        diagram with the given tags (in addition to the specific</span>
<span class="sd">        tag for this thing).  flip=1 means draw left to right;</span>
<span class="sd">        flip=-1 means right to left.  Return a list of Things</span>
<span class="sd">        that were drawn.</span>

<span class="sd">        draw and drawme are not allowed to mofify pos</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">isdrawn</span><span class="p">():</span>
            <span class="k">return</span> <span class="p">[]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">drawn</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span> <span class="o">=</span> <span class="n">diag</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span> <span class="o">=</span> <span class="n">diag</span><span class="o">.</span><span class="n">canvas</span>

        <span class="c"># keep track of how many things have been drawn.</span>
        <span class="c"># Simple values can get drawn more than once, so the</span>
        <span class="c"># total number of things drawn can be greater than</span>
        <span class="c"># the number of things.</span>
        <span class="n">Thing</span><span class="o">.</span><span class="n">things_drawn</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="n">Thing</span><span class="o">.</span><span class="n">things_drawn</span> <span class="o">%</span> <span class="mi">100</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">print</span> <span class="n">Thing</span><span class="o">.</span><span class="n">things_drawn</span>
            <span class="c">#self.diag.lumpy.update()</span>

        <span class="c"># each thing has a list of tags: its own tag plus</span>
        <span class="c"># the tag of each thing it belongs to.  This convention</span>
        <span class="c"># makes it possible to move entire structures with one</span>
        <span class="c"># move command.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tags</span> <span class="o">=</span> <span class="n">make_tags</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span><span class="p">)</span>
        <span class="n">tags</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tags</span>

        <span class="c"># invoke drawme in the child class</span>
        <span class="n">drawn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">drawme</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">drawn</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">drawn</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="p">]</span>
            
        <span class="bp">self</span><span class="o">.</span><span class="n">set_offset</span><span class="p">(</span><span class="n">pos</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">drawn</span>
</div>
<div class="viewcode-block" id="Thing.bind"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.bind">[docs]</a>    <span class="k">def</span> <span class="nf">bind</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;create bindings for each of the items with the given tags</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">tags</span> <span class="o">=</span> <span class="n">tags</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">tags</span>
        <span class="n">items</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">find_withtag</span><span class="p">(</span><span class="n">tags</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">tag_bind</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="s">&quot;&lt;Button-1&gt;&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">down</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Thing.down"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.down">[docs]</a>    <span class="k">def</span> <span class="nf">down</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;this callback is invoked when the user clicks on an item</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dragpos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">invert</span><span class="p">([</span><span class="n">event</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">event</span><span class="o">.</span><span class="n">y</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&quot;&lt;B1-Motion&gt;&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">motion</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&quot;&lt;ButtonRelease-1&gt;&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">up</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">True</span>
</div>
<div class="viewcode-block" id="Thing.motion"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.motion">[docs]</a>    <span class="k">def</span> <span class="nf">motion</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;this callback is invoked when the user drags an item&quot;&quot;&quot;</span>
        <span class="n">newpos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">invert</span><span class="p">([</span><span class="n">event</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">event</span><span class="o">.</span><span class="n">y</span><span class="p">])</span>
        <span class="n">dx</span> <span class="o">=</span> <span class="n">newpos</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">dragpos</span><span class="o">.</span><span class="n">x</span>
        <span class="n">dy</span> <span class="o">=</span> <span class="n">newpos</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">dragpos</span><span class="o">.</span><span class="n">y</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">tmove</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tags</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dragpos</span> <span class="o">=</span> <span class="n">newpos</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="o">.</span><span class="n">update_arrows</span><span class="p">()</span>
  </div>
<div class="viewcode-block" id="Thing.up"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Thing.up">[docs]</a>    <span class="k">def</span> <span class="nf">up</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;this callback is invoked when the user releases the button&quot;&quot;&quot;</span>
        <span class="n">event</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">unbind</span> <span class="p">(</span><span class="s">&quot;&lt;B1-Motion&gt;&quot;</span><span class="p">)</span>
        <span class="n">event</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">unbind</span> <span class="p">(</span><span class="s">&quot;&lt;ButtonRelease-1&gt;&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="o">.</span><span class="n">update_arrows</span><span class="p">()</span>

</div></div>
<div class="viewcode-block" id="Dot"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Dot">[docs]</a><span class="k">class</span> <span class="nc">Dot</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the Thing that represents a dot in a diagram&quot;&quot;&quot;</span>
<div class="viewcode-block" id="Dot.drawme"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Dot.drawme">[docs]</a>    <span class="k">def</span> <span class="nf">drawme</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">pos</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>

</div></div>
<div class="viewcode-block" id="Simple"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Simple">[docs]</a><span class="k">class</span> <span class="nc">Simple</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the graphical representation of a simple value like a number</span>
<span class="sd">    or a string&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="n">lumpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">val</span> <span class="o">=</span> <span class="n">val</span>

<div class="viewcode-block" id="Simple.drawme"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Simple.drawme">[docs]</a>    <span class="k">def</span> <span class="nf">drawme</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="n">flip</span>        
        <span class="n">anchor</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">:</span><span class="n">W</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">E</span><span class="p">}</span>

        <span class="c"># put quotes around strings; for everything else, use</span>
        <span class="c"># the standard str representation</span>
        <span class="n">val</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">val</span>
        <span class="n">maxlen</span> <span class="o">=</span> <span class="mi">30</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">val</span> <span class="o">=</span> <span class="n">val</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="p">)</span>
            <span class="n">label</span> <span class="o">=</span> <span class="s">&quot;&#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> <span class="n">val</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">maxlen</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">label</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">str</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="n">anchor</span><span class="p">[</span><span class="n">flip</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bind</span><span class="p">()</span>

</div></div>
<div class="viewcode-block" id="Index"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Index">[docs]</a><span class="k">class</span> <span class="nc">Index</span><span class="p">(</span><span class="n">Simple</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the graphical representation of an index in a Sequence.</span>
<span class="sd">    An Index object does not register with lumpy, so that even</span>
<span class="sd">    in pedantic mode, it is always drawn, and it is never the</span>
<span class="sd">    target of a reference (since it is not really a value at</span>
<span class="sd">    run-time).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">val</span> <span class="o">=</span> <span class="n">val</span>

<div class="viewcode-block" id="Index.drawme"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Index.drawme">[docs]</a>    <span class="k">def</span> <span class="nf">drawme</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="n">flip</span>        
        <span class="n">anchor</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">:</span><span class="n">W</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">E</span><span class="p">}</span>

        <span class="n">label</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">val</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">str</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="n">anchor</span><span class="p">[</span><span class="n">flip</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bind</span><span class="p">()</span>
</div></div>
<div class="viewcode-block" id="Mapping"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Mapping">[docs]</a><span class="k">class</span> <span class="nc">Mapping</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the graphical representation of a mapping type (usually a</span>
<span class="sd">    dictionary).  Sequence and Instance inherit from Mapping.&quot;&quot;&quot;</span>
    
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="n">lumpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bindings</span> <span class="o">=</span> <span class="n">make_kvps</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="s">&#39;purple&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">pedantic</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="o">.</span><span class="n">__name__</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>

<div class="viewcode-block" id="Mapping.bbox"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Mapping.bbox">[docs]</a>    <span class="k">def</span> <span class="nf">bbox</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;the bbox of a Mapping is the bbox of its box item.</span>
<span class="sd">        This is different from other Things.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">boxitem</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Mapping.drawme"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Mapping.drawme">[docs]</a>    <span class="k">def</span> <span class="nf">drawme</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="sd">&quot;&quot;&quot;drawme is the middle part of the way objects are drawn.</span>
<span class="sd">        Thing.draw does some prep work, invokes drawme, and then</span>
<span class="sd">        does some cleanup.  draw and drawme are not allowed to</span>
<span class="sd">        modify pos.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

        <span class="c"># intag is attached to items that should be considered</span>
        <span class="c"># inside the box</span>
        <span class="n">intag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tags</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39;inside&#39;</span>

        <span class="c"># draw the bindings</span>
        <span class="k">for</span> <span class="n">binding</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bindings</span><span class="p">:</span>
            <span class="c"># check whether the key was already drawn</span>
            <span class="n">drawn</span> <span class="o">=</span> <span class="n">binding</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">isdrawn</span><span class="p">()</span>

            <span class="c"># draw the binding</span>
            <span class="n">binding</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>

            <span class="c"># apply intag to the dots </span>
            <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">addtag_withtag</span><span class="p">(</span><span class="n">intag</span><span class="p">,</span> <span class="n">binding</span><span class="o">.</span><span class="n">dot</span><span class="o">.</span><span class="n">tags</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">drawn</span><span class="p">:</span>
                <span class="c"># if the key was already drawn, then the binding</span>
                <span class="c"># contains two dots, so we should add intag to the</span>
                <span class="c"># second one.</span>
                <span class="k">if</span> <span class="n">binding</span><span class="o">.</span><span class="n">dot2</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">addtag_withtag</span><span class="p">(</span><span class="n">intag</span><span class="p">,</span> <span class="n">binding</span><span class="o">.</span><span class="n">dot2</span><span class="o">.</span><span class="n">tags</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># if the key wasn&#39;t drawn yet, it should be</span>
                <span class="c"># considered inside this mapping</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">addtag_withtag</span><span class="p">(</span><span class="n">intag</span><span class="p">,</span> <span class="n">binding</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">tags</span><span class="p">)</span>

            <span class="c"># move down to the position for the next binding</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">binding</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span><span class="o">.</span><span class="n">bottom</span> <span class="o">+</span> <span class="mf">1.8</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bindings</span><span class="p">):</span>
            <span class="c"># if there are any bindings, draw a box around them</span>
            <span class="n">bbox</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="n">intag</span><span class="p">)</span>
            <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">box</span><span class="p">(</span><span class="n">bbox</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># otherwise just draw a box</span>
            <span class="n">bbox</span> <span class="o">=</span> <span class="n">BBox</span><span class="p">([</span><span class="n">p</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">p</span><span class="o">.</span><span class="n">copy</span><span class="p">()])</span>
            <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">box</span><span class="p">(</span><span class="n">bbox</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mf">0.4</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mf">0.4</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">,</span>
                              <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span><span class="p">)</span>

        <span class="c"># make the box clickable</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">boxitem</span> <span class="o">=</span> <span class="n">item</span>

        <span class="c"># put the label above the box</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">:</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">bbox</span><span class="o">.</span><span class="n">upperleft</span><span class="p">()</span>
            <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">str</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="n">SW</span><span class="p">,</span>
                              <span class="n">font</span><span class="o">=</span><span class="n">smallfont</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
            <span class="c"># make the label clickable</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="c"># if the whole mapping is not in the right position, shift it.</span>
        <span class="k">if</span> <span class="n">flip</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">dx</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span><span class="o">.</span><span class="n">left</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">dx</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span><span class="o">.</span><span class="n">right</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">tmove</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tags</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Mapping.scan_bindings"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Mapping.scan_bindings">[docs]</a>    <span class="k">def</span> <span class="nf">scan_bindings</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cls</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;scan the bindings in this mapping, looking for</span>
<span class="sd">        references to other object types.  cls is the Class</span>
<span class="sd">        of the object that contains this mapping&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">binding</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bindings</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">binding</span><span class="o">.</span><span class="n">vals</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">scan_val</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Mapping.scan_val"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Mapping.scan_val">[docs]</a>    <span class="k">def</span> <span class="nf">scan_val</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cls</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;if we find a reference to an object type, make a note</span>
<span class="sd">        of the HAS-A relationship.  If we find a reference to a</span>
<span class="sd">        container type, scan it for references.&quot;&quot;&quot;</span>        
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">Instance</span><span class="p">)</span> <span class="ow">and</span> <span class="n">val</span><span class="o">.</span><span class="n">cls</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">cls</span><span class="o">.</span><span class="n">add_hasa</span><span class="p">(</span><span class="n">val</span><span class="o">.</span><span class="n">cls</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">Sequence</span><span class="p">):</span>
            <span class="n">val</span><span class="o">.</span><span class="n">scan_bindings</span><span class="p">(</span><span class="n">cls</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">Mapping</span><span class="p">):</span>
            <span class="n">val</span><span class="o">.</span><span class="n">scan_bindings</span><span class="p">(</span><span class="n">cls</span><span class="p">)</span>
        
</div></div>
<div class="viewcode-block" id="Sequence"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Sequence">[docs]</a><span class="k">class</span> <span class="nc">Sequence</span><span class="p">(</span><span class="n">Mapping</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the graphical representation of a sequence type (mostly</span>
<span class="sd">    lists and tuples)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="n">lumpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bindings</span> <span class="o">=</span> <span class="n">make_bindings</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">val</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">pedantic</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="o">.</span><span class="n">__name__</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>

        <span class="c"># color code lists, tuples, and other sequences</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="s">&#39;green1&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="s">&#39;green4&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="s">&#39;green2&#39;</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="Instance"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Instance">[docs]</a><span class="k">class</span> <span class="nc">Instance</span><span class="p">(</span><span class="n">Mapping</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;The graphical representation of an object (usually).</span>
<span class="sd">    Anything with a __dict__ is treated as an Instance.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="n">lumpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>

        <span class="c"># if this object has a class, make a Thing to</span>
        <span class="c"># represent the class, too</span>
        <span class="k">if</span> <span class="n">hasclass</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
            <span class="n">class_or_type</span> <span class="o">=</span> <span class="n">val</span><span class="o">.</span><span class="n">__class__</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cls</span> <span class="o">=</span> <span class="n">make_thing</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">class_or_type</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">class_or_type</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cls</span> <span class="o">=</span> <span class="bp">None</span>
            
        <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="n">class_or_type</span><span class="o">.</span><span class="n">__name__</span>

        <span class="k">if</span> <span class="n">class_or_type</span> <span class="ow">in</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">instance_vars</span><span class="p">:</span>
            <span class="c"># if the class is in the list, only display only the</span>
            <span class="c"># unrestricted instance variables</span>
            <span class="n">ks</span> <span class="o">=</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">instance_vars</span><span class="p">[</span><span class="n">class_or_type</span><span class="p">]</span>
            <span class="nb">iter</span> <span class="o">=</span> <span class="p">[(</span><span class="n">k</span><span class="p">,</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">ks</span><span class="p">]</span>
            <span class="n">seq</span> <span class="o">=</span> <span class="n">make_bindings</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="nb">iter</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># otherwise, display all of the instance variables</span>
            <span class="k">if</span> <span class="n">hasdict</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
                <span class="nb">iter</span> <span class="o">=</span> <span class="n">val</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">iteritems</span><span class="p">()</span>
            <span class="k">elif</span> <span class="n">hasslots</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
                <span class="nb">iter</span> <span class="o">=</span> <span class="p">[(</span><span class="n">k</span><span class="p">,</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">val</span><span class="o">.</span><span class="n">__slots__</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">t</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">type</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">iteritems</span><span class="p">()</span>
                     <span class="k">if</span> <span class="nb">str</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&#39;attribute&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">]</span>
                <span class="nb">iter</span> <span class="o">=</span> <span class="p">[(</span><span class="n">k</span><span class="p">,</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">t</span><span class="p">]</span>
            
            <span class="n">seq</span> <span class="o">=</span> <span class="n">make_bindings</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="nb">iter</span><span class="p">)</span>

            <span class="c"># and if the object extends list, tuple or dict,</span>
            <span class="c"># append the items</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
                <span class="n">seq</span> <span class="o">+=</span> <span class="n">make_bindings</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">val</span><span class="p">))</span>

            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
                <span class="n">seq</span> <span class="o">+=</span> <span class="n">make_bindings</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="o">.</span><span class="n">iteritems</span><span class="p">())</span>

        <span class="c"># if this instance has a name attribute, show it</span>
        <span class="n">attr</span> <span class="o">=</span> <span class="s">&#39;__name__&#39;</span>
        <span class="k">if</span> <span class="n">hasname</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
            <span class="n">seq</span> <span class="o">+=</span> <span class="n">make_bindings</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="p">[[</span><span class="n">attr</span><span class="p">,</span> <span class="n">val</span><span class="o">.</span><span class="n">__name__</span><span class="p">]])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">bindings</span> <span class="o">=</span> <span class="n">seq</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="s">&#39;red&#39;</span><span class="p">)</span>

<div class="viewcode-block" id="Instance.scan_bindings"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Instance.scan_bindings">[docs]</a>    <span class="k">def</span> <span class="nf">scan_bindings</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cls</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;scan the bindings in this Instance, looking for</span>
<span class="sd">        references to other object types; also, make a note</span>
<span class="sd">        of the names of the instance variables.</span>
<span class="sd">        cls is the Class object this instance belongs to.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">binding</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bindings</span><span class="p">:</span>
            <span class="n">cls</span><span class="o">.</span><span class="n">add_ivar</span><span class="p">(</span><span class="n">binding</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">val</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">binding</span><span class="o">.</span><span class="n">vals</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">scan_val</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
</div></div>
<div class="viewcode-block" id="Frame"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Frame">[docs]</a><span class="k">class</span> <span class="nc">Frame</span><span class="p">(</span><span class="n">Mapping</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;The graphical representation of a frame,</span>
<span class="sd">    implemented as a list of Bindings&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">frame</span><span class="p">):</span>
        <span class="nb">iter</span> <span class="o">=</span> <span class="n">frame</span><span class="o">.</span><span class="n">locals</span><span class="o">.</span><span class="n">iteritems</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bindings</span> <span class="o">=</span> <span class="n">make_bindings</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="nb">iter</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="n">frame</span><span class="o">.</span><span class="n">func</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="s">&#39;blue&#39;</span><span class="p">)</span>
    


<span class="c"># the following are short functions that check for certain attributes</span></div>
<div class="viewcode-block" id="hasname"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.hasname">[docs]</a><span class="k">def</span> <span class="nf">hasname</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s">&#39;__name__&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="hasclass"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.hasclass">[docs]</a><span class="k">def</span> <span class="nf">hasclass</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s">&#39;__class__&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="hasdict"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.hasdict">[docs]</a><span class="k">def</span> <span class="nf">hasdict</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s">&#39;__dict__&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="hasslots"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.hasslots">[docs]</a><span class="k">def</span> <span class="nf">hasslots</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s">&#39;__slots__&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="hasdiag"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.hasdiag">[docs]</a><span class="k">def</span> <span class="nf">hasdiag</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s">&#39;diag&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="iscallable"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.iscallable">[docs]</a><span class="k">def</span> <span class="nf">iscallable</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s">&#39;__call__&#39;</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="Class"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Class">[docs]</a><span class="k">class</span> <span class="nc">Class</span><span class="p">(</span><span class="n">Instance</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;a graphical representation of a Class.  It inherits</span>
<span class="sd">    from Instance, which controls how a Class appears in an</span>
<span class="sd">    object diagram, and contains a ClassDiagramClass, which</span>
<span class="sd">    controls how the Class appears in a class diagram.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">classobj</span><span class="p">):</span>
        <span class="n">Instance</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">classobj</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cdc</span> <span class="o">=</span> <span class="n">ClassDiagramClass</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">classobj</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cdc</span><span class="o">.</span><span class="n">cls</span> <span class="o">=</span> <span class="bp">self</span>
        
        <span class="n">lumpy</span><span class="o">.</span><span class="n">classes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">classobj</span> <span class="o">=</span> <span class="n">classobj</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">module</span> <span class="o">=</span> <span class="n">classobj</span><span class="o">.</span><span class="n">__module__</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bases</span> <span class="o">=</span> <span class="n">classobj</span><span class="o">.</span><span class="n">__bases__</span>

        <span class="c"># childs is the list of classes that inherit directly</span>
        <span class="c"># from this one; parents is the list of base classes</span>
        <span class="c"># for this one</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">childs</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c"># refers is a dictionary that records, for each other</span>
        <span class="c"># class, the total number of references we have found from</span>
        <span class="c"># this class to that</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">refers</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="c"># make a list of Things to represent the</span>
        <span class="c"># parent classes</span>
        <span class="k">if</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">is_opaque</span><span class="p">(</span><span class="n">classobj</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">parents</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">parents</span> <span class="o">=</span> <span class="p">[</span><span class="n">make_thing</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">base</span><span class="p">)</span> <span class="k">for</span> <span class="n">base</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bases</span><span class="p">]</span>

        <span class="c"># add self to the parents&#39; lists of children</span>
        <span class="k">for</span> <span class="n">parent</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parents</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="c"># height and depth are used to lay out the tree</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">height</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">depth</span> <span class="o">=</span> <span class="bp">None</span>
        
<div class="viewcode-block" id="Class.add_child"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Class.add_child">[docs]</a>    <span class="k">def</span> <span class="nf">add_child</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">child</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;when a subclass is created, it notifies its parent</span>
<span class="sd">        classes, who update their list of children&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">childs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">child</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Class.add_hasa"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Class.add_hasa">[docs]</a>    <span class="k">def</span> <span class="nf">add_hasa</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">child</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;increment the number of references we have found</span>
<span class="sd">        from this class to the given child class&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">refers</span><span class="p">[</span><span class="n">child</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">refers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">child</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="n">n</span>
</div>
<div class="viewcode-block" id="Class.set_height"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Class.set_height">[docs]</a>    <span class="k">def</span> <span class="nf">set_height</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;compute the maximum height between this class and</span>
<span class="sd">        a leaf class (one with no children)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">height</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">childs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">height</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">return</span>
        <span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">childs</span><span class="p">:</span>
            <span class="n">child</span><span class="o">.</span><span class="n">set_height</span><span class="p">()</span>
            
        <span class="n">heights</span> <span class="o">=</span> <span class="p">[</span><span class="n">child</span><span class="o">.</span><span class="n">height</span> <span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">childs</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">height</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">heights</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
</div>
<div class="viewcode-block" id="Class.set_depth"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Class.set_depth">[docs]</a>    <span class="k">def</span> <span class="nf">set_depth</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;compute the maximum depth between this class and</span>
<span class="sd">        a root class (one with no parents)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">depth</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">parents</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">depth</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">return</span>
        <span class="k">for</span> <span class="n">parent</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parents</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">set_depth</span><span class="p">()</span>
            
        <span class="n">depths</span> <span class="o">=</span> <span class="p">[</span><span class="n">parent</span><span class="o">.</span><span class="n">depth</span> <span class="k">for</span> <span class="n">parent</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parents</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">depth</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">depths</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
</div>
<div class="viewcode-block" id="Class.add_ivar"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Class.add_ivar">[docs]</a>    <span class="k">def</span> <span class="nf">add_ivar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">var</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;add to the set of instance variables for this class</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cdc</span><span class="o">.</span><span class="n">ivars</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">var</span><span class="p">)</span>

</div></div>
<div class="viewcode-block" id="ClassDiagramClass"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ClassDiagramClass">[docs]</a><span class="k">class</span> <span class="nc">ClassDiagramClass</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;a graphical representation of a Class as it appears</span>
<span class="sd">    in a Class Diagram (which is different from the way class</span>
<span class="sd">    objects appear in Object Diagrams).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">classobj</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span> <span class="o">=</span> <span class="n">lumpy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">classobj</span> <span class="o">=</span> <span class="n">classobj</span>

        <span class="c"># self.methods is the list of methods defined in this class.</span>
        <span class="c"># self.cvars is the list of class variables.</span>
        <span class="c"># self.ivars is a set of instance variables.</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">methods</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cvars</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ivars</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>

        <span class="c"># if this is a restricted (or opaque) class, then</span>
        <span class="c"># vars contains the list of instance variables that</span>
        <span class="c"># will be shown; otherwise it is None.</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="nb">vars</span> <span class="o">=</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">instance_vars</span><span class="p">[</span><span class="n">classobj</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="nb">vars</span> <span class="o">=</span> <span class="bp">None</span>

        <span class="c"># we can get methods and class variables now, but we</span>
        <span class="c"># have to wait until the Lumpy representation of the stack</span>
        <span class="c"># is complete before we can go looking for instance vars.</span>
        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">classobj</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">vars</span> <span class="o">!=</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="nb">vars</span><span class="p">:</span> <span class="k">continue</span>
            
            <span class="k">if</span> <span class="n">iscallable</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">cvars</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cvars</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="s">&#39;blue&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lineoptions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">fill</span><span class="o">=</span><span class="s">&#39;blue&#39;</span><span class="p">)</span>


<div class="viewcode-block" id="ClassDiagramClass.drawme"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ClassDiagramClass.drawme">[docs]</a>    <span class="k">def</span> <span class="nf">drawme</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

        <span class="c"># draw the name of the class</span>
        <span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">classobj</span><span class="o">.</span><span class="n">__name__</span>
        <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">str</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
        <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mf">0.8</span>

        <span class="c"># in order to draw lines between segments, we have</span>
        <span class="c"># to store the locations and draw the lines, later,</span>
        <span class="c"># when we know the location of the box</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c"># draw a line between the name and the methods</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c"># draw the methods</span>
        <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="p">:</span>
            <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">str</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c"># draw the class variables</span>
        <span class="n">cvars</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cvars</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">cvars</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;__doc__&#39;</span><span class="p">)</span>
            <span class="n">cvars</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;__module__&#39;</span><span class="p">)</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">pass</span>
        
        <span class="c"># draw the class variables</span>
        <span class="k">if</span> <span class="n">cvars</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="k">for</span> <span class="n">varname</span> <span class="ow">in</span> <span class="n">cvars</span><span class="p">:</span>
            <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">str</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">varname</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c"># if this is a restricted (or opaque) class, remove</span>
        <span class="c"># unwanted instance vars from self.ivars</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="nb">vars</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">instance_vars</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">classobj</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ivars</span><span class="o">.</span><span class="n">intersection_update</span><span class="p">(</span><span class="nb">vars</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">pass</span>
            
        <span class="c"># draw the instance variables</span>
        <span class="n">ivars</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ivars</span><span class="p">)</span>
        <span class="n">ivars</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">ivars</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="k">for</span> <span class="n">varname</span> <span class="ow">in</span> <span class="n">ivars</span><span class="p">:</span>
            <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">str</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">varname</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c"># draw the box</span>
        <span class="n">bbox</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span>
        <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">box</span><span class="p">(</span><span class="n">bbox</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">boxoptions</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">boxitem</span> <span class="o">=</span> <span class="n">item</span>

        <span class="c"># draw the lines</span>
        <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">:</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="p">[[</span><span class="n">bbox</span><span class="o">.</span><span class="n">left</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="n">bbox</span><span class="o">.</span><span class="n">right</span><span class="p">,</span> <span class="n">y</span><span class="p">]]</span>
            <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">line</span><span class="p">(</span><span class="n">coords</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">lineoptions</span><span class="p">)</span>

        <span class="c"># only the things we have drawn so far should be bound</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bind</span><span class="p">()</span>

        <span class="c"># make a list of all classes drawn</span>
        <span class="n">alldrawn</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="p">]</span>

        <span class="c"># draw the descendents of this class</span>
        <span class="n">childs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cls</span><span class="o">.</span><span class="n">childs</span>

        <span class="k">if</span> <span class="n">childs</span><span class="p">:</span>
            <span class="n">q</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">q</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">bbox</span><span class="o">.</span><span class="n">right</span> <span class="o">+</span> <span class="mi">8</span>
            
            <span class="n">drawn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="o">.</span><span class="n">draw_classes</span><span class="p">(</span><span class="n">childs</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">tags</span><span class="p">)</span>
            <span class="n">alldrawn</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">drawn</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">head</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrow_head</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">bbox</span><span class="p">,</span> <span class="n">tags</span><span class="p">)</span>

            <span class="c"># connect this class to its children</span>
            <span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">childs</span><span class="p">:</span>
                <span class="n">a</span> <span class="o">=</span> <span class="n">ParentArrow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">child</span><span class="o">.</span><span class="n">cdc</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="o">.</span><span class="n">add_arrow</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>

        <span class="c"># if the class is not in the right position, shift it.</span>
        <span class="n">dx</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span><span class="o">.</span><span class="n">left</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tags</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">alldrawn</span>
</div>
<div class="viewcode-block" id="ClassDiagramClass.arrow_head"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ClassDiagramClass.arrow_head">[docs]</a>    <span class="k">def</span> <span class="nf">arrow_head</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">bbox</span><span class="p">,</span> <span class="n">tags</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mf">0.5</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw the hollow arrow head that connects this class</span>
<span class="sd">        to its children.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">bbox</span><span class="o">.</span><span class="n">midright</span><span class="p">()</span>
        <span class="n">x</span> <span class="o">+=</span> <span class="mf">0.1</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="p">[[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="o">+</span><span class="n">size</span><span class="p">,</span> <span class="n">y</span><span class="o">+</span><span class="n">size</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="o">+</span><span class="n">size</span><span class="p">,</span> <span class="n">y</span><span class="o">-</span><span class="n">size</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">]]</span>
        <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">line</span><span class="p">(</span><span class="n">coords</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">lineoptions</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">item</span>

</div></div>
<div class="viewcode-block" id="Binding"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Binding">[docs]</a><span class="k">class</span> <span class="nc">Binding</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the graphical representation of the binding between a</span>
<span class="sd">    key and a value.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="n">lumpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="n">key</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">vals</span> <span class="o">=</span> <span class="p">[</span><span class="n">val</span><span class="p">]</span>

<div class="viewcode-block" id="Binding.rebind"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Binding.rebind">[docs]</a>    <span class="k">def</span> <span class="nf">rebind</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">val</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Binding.draw_key"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Binding.draw_key">[docs]</a>    <span class="k">def</span> <span class="nf">draw_key</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw a reference to a previously-drawn key rather</span>
<span class="sd">        than drawing the key inside the mapping.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">-=</span> <span class="mf">0.7</span> <span class="o">*</span> <span class="n">flip</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dot2</span> <span class="o">=</span> <span class="n">Dot</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dot2</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="o">-</span><span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>

        <span class="c"># only the things we have drawn so far should</span>
        <span class="c"># be handles for this binding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bind</span><span class="p">()</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">isdrawn</span><span class="p">():</span>
            <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">-=</span> <span class="mf">2.0</span> <span class="o">*</span> <span class="n">flip</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="o">-</span><span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
        <span class="n">a</span> <span class="o">=</span> <span class="n">ReferenceArrow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dot2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;orange&#39;</span><span class="p">)</span>
        <span class="n">diag</span><span class="o">.</span><span class="n">add_arrow</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
        
</div>
<div class="viewcode-block" id="Binding.drawme"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Binding.drawme">[docs]</a>    <span class="k">def</span> <span class="nf">drawme</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dot</span> <span class="o">=</span> <span class="n">Dot</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dot</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
        
        <span class="n">p</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">-=</span> <span class="mf">0.7</span> <span class="o">*</span> <span class="n">flip</span>

        <span class="c"># if the key is a Simple, try to draw it inside the mapping;</span>
        <span class="c"># otherwise, draw a reference to it</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="p">,</span> <span class="n">Simple</span><span class="p">):</span>
            <span class="n">drawn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="o">-</span><span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>

            <span class="c"># if a Simple thing doesn&#39;t get drawn, we must be in</span>
            <span class="c"># pedantic mode.</span>
            <span class="k">if</span> <span class="n">drawn</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">bind</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dot2</span> <span class="o">=</span> <span class="bp">None</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">draw_key</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="p">)</span>                
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">draw_key</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="p">)</span>                

        <span class="n">p</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="mf">2.0</span> <span class="o">*</span> <span class="n">flip</span>

        <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">vals</span><span class="p">:</span>
            <span class="n">val</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">ReferenceArrow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dot</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;orange&#39;</span><span class="p">)</span>
            <span class="n">diag</span><span class="o">.</span><span class="n">add_arrow</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="mi">1</span>

</div></div>
<div class="viewcode-block" id="ReferenceArrow"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ReferenceArrow">[docs]</a><span class="k">class</span> <span class="nc">ReferenceArrow</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;a reference arrow, which show a reference in an object diagram</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span> <span class="o">=</span> <span class="n">lumpy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="n">key</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">val</span> <span class="o">=</span> <span class="n">val</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="n">options</span>
        
<div class="viewcode-block" id="ReferenceArrow.draw"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ReferenceArrow.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span> <span class="o">=</span> <span class="n">diag</span>
        <span class="n">canvas</span> <span class="o">=</span> <span class="n">diag</span><span class="o">.</span><span class="n">canvas</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">item</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">arrow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">pos</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">val</span><span class="o">.</span><span class="n">pos</span><span class="p">(),</span>
                                 <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">)</span>
        <span class="n">canvas</span><span class="o">.</span><span class="n">lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">item</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ReferenceArrow.update"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ReferenceArrow.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">hasdiag</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">tcoords</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">item</span><span class="p">,</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">pos</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">val</span><span class="o">.</span><span class="n">pos</span><span class="p">()])</span>

</div></div>
<div class="viewcode-block" id="ParentArrow"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ParentArrow">[docs]</a><span class="k">class</span> <span class="nc">ParentArrow</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;an inheritance arrow, which shows an is-a relationship</span>
<span class="sd">    between classes in a class diagram.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">child</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span> <span class="o">=</span> <span class="n">lumpy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">child</span> <span class="o">=</span> <span class="n">child</span>
        <span class="n">underride</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;blue&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="n">options</span>
        
<div class="viewcode-block" id="ParentArrow.draw"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ParentArrow.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span> <span class="o">=</span> <span class="n">diag</span>
        <span class="n">parent</span><span class="p">,</span> <span class="n">child</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">child</span>

        <span class="c"># the line connects the midleft point of the child</span>
        <span class="c"># to the arrowhead of the parent; it always contains</span>
        <span class="c"># two horizontal segments and one vertical.</span>
        <span class="n">canvas</span> <span class="o">=</span> <span class="n">diag</span><span class="o">.</span><span class="n">canvas</span>
        <span class="n">bbox</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">head</span><span class="p">)</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">bbox</span><span class="o">.</span><span class="n">midright</span><span class="p">()</span>
        <span class="n">q</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="n">child</span><span class="o">.</span><span class="n">boxitem</span><span class="p">)</span><span class="o">.</span><span class="n">midleft</span><span class="p">()</span>
        <span class="n">midx</span> <span class="o">=</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="n">q</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">/</span> <span class="mf">2.0</span>
        <span class="n">m1</span> <span class="o">=</span> <span class="p">[</span><span class="n">midx</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">]</span>
        <span class="n">m2</span> <span class="o">=</span> <span class="p">[</span><span class="n">midx</span><span class="p">,</span> <span class="n">q</span><span class="o">.</span><span class="n">y</span><span class="p">]</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span><span class="p">,</span> <span class="n">m1</span><span class="p">,</span> <span class="n">m2</span><span class="p">,</span> <span class="n">q</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">item</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">line</span><span class="p">(</span><span class="n">coords</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">)</span>
        <span class="n">canvas</span><span class="o">.</span><span class="n">lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">item</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ParentArrow.update"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ParentArrow.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">hasdiag</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">item</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="p">)</span>

</div></div>
<div class="viewcode-block" id="ContainsArrow"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ContainsArrow">[docs]</a><span class="k">class</span> <span class="nc">ContainsArrow</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;a contains arrow, which shows a has-a relationship between</span>
<span class="sd">    classes in a class diagram.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">child</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span> <span class="o">=</span> <span class="n">lumpy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">child</span> <span class="o">=</span> <span class="n">child</span>
        <span class="n">underride</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;orange&#39;</span><span class="p">,</span> <span class="n">arrow</span><span class="o">=</span><span class="n">LAST</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="n">options</span>
        
<div class="viewcode-block" id="ContainsArrow.draw"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ContainsArrow.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span> <span class="o">=</span> <span class="n">diag</span>
        <span class="n">parent</span><span class="p">,</span> <span class="n">child</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">child</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">child</span><span class="o">.</span><span class="n">isdrawn</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">item</span> <span class="o">=</span> <span class="bp">None</span>
            <span class="k">return</span>
        
        <span class="n">canvas</span> <span class="o">=</span> <span class="n">diag</span><span class="o">.</span><span class="n">canvas</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">boxitem</span><span class="p">)</span><span class="o">.</span><span class="n">midleft</span><span class="p">()</span>
        <span class="n">q</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="n">child</span><span class="o">.</span><span class="n">boxitem</span><span class="p">)</span><span class="o">.</span><span class="n">midright</span><span class="p">()</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span><span class="p">,</span> <span class="n">q</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">item</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">line</span><span class="p">(</span><span class="n">coords</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">)</span>
        <span class="n">canvas</span><span class="o">.</span><span class="n">lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">item</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ContainsArrow.update"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ContainsArrow.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">hasdiag</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">item</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">diag</span><span class="p">)</span>


</div></div>
<div class="viewcode-block" id="Stack"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Stack">[docs]</a><span class="k">class</span> <span class="nc">Stack</span><span class="p">(</span><span class="n">Thing</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;The graphical representation of a stack.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">snapshot</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span> <span class="o">=</span> <span class="n">lumpy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">frames</span> <span class="o">=</span> <span class="p">[</span><span class="n">Frame</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">frame</span><span class="p">)</span> <span class="k">for</span> <span class="n">frame</span> <span class="ow">in</span> <span class="n">snapshot</span><span class="o">.</span><span class="n">frames</span><span class="p">]</span>
    
<div class="viewcode-block" id="Stack.drawme"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Stack.drawme">[docs]</a>    <span class="k">def</span> <span class="nf">drawme</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        
        <span class="k">for</span> <span class="n">frame</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">frames</span><span class="p">:</span>
            <span class="n">frame</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diag</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">flip</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="n">tags</span><span class="p">)</span>
            <span class="n">bbox</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span>
            <span class="c">#p.y = bbox.bottom + 3</span>
            <span class="n">p</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">bbox</span><span class="o">.</span><span class="n">right</span> <span class="o">+</span> <span class="mi">3</span>

</div></div>
<div class="viewcode-block" id="make_bindings"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.make_bindings">[docs]</a><span class="k">def</span> <span class="nf">make_bindings</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">iterator</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;return a list of bindings, one for each key-value pair</span>
<span class="sd">    in iterator.  The keys are made into Index objects.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">seq</span> <span class="o">=</span> <span class="p">[</span><span class="n">Binding</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">Index</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="n">make_thing</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span>
           <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">iterator</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">seq</span>

</div>
<div class="viewcode-block" id="make_kvps"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.make_kvps">[docs]</a><span class="k">def</span> <span class="nf">make_kvps</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">iterator</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;return a list of bindings, one for each key-value pair</span>
<span class="sd">    in iterator.  The keys are made into Thing objects.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">seq</span> <span class="o">=</span> <span class="p">[</span><span class="n">Binding</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">make_thing</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="n">make_thing</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span>
           <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">iterator</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">seq</span>


<span class="c"># hpl code:</span></div>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">numpy</span>
<div class="viewcode-block" id="NumPyArray"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.NumPyArray">[docs]</a>    <span class="k">class</span> <span class="nc">NumPyArray</span><span class="p">:</span>
        <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">array</span> <span class="o">=</span> <span class="s">&#39;x&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">])</span></div>
    <span class="n">numpy_array_type</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ndarray</span>
<span class="k">except</span><span class="p">:</span>
    <span class="c"># no numpy</span>
    <span class="k">class</span> <span class="nc">Dummy</span><span class="p">:</span>
        <span class="k">pass</span>
    <span class="n">numpy_array_type</span> <span class="o">=</span> <span class="n">Dummy</span>
<span class="c"># end of hpl code</span>


<div class="viewcode-block" id="make_thing"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.make_thing">[docs]</a><span class="k">def</span> <span class="nf">make_thing</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;return the Thing that represents this value, either</span>
<span class="sd">    by making a new one or looking up an existing one.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c"># if we&#39;re being pedantic, then we always show aliased</span>
    <span class="c"># values</span>
    <span class="k">if</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">pedantic</span><span class="p">:</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">thing</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> <span class="k">return</span> <span class="n">thing</span>

    <span class="c"># otherwise for simple immutable types, ignore aliasing and</span>
    <span class="c"># just draw</span>
    <span class="n">simple</span> <span class="o">=</span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">long</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">complex</span><span class="p">,</span> <span class="n">NoneType</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">simple</span><span class="p">):</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">Simple</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">thing</span>

    <span class="c"># now check for aliasing even if we&#39;re not pedantic</span>
    <span class="n">thing</span> <span class="o">=</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">thing</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> <span class="k">return</span> <span class="n">thing</span>

    <span class="c"># check the type of the value and dispatch accordingly</span>
    <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="n">Lumpy</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">type</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="nb">int</span><span class="p">)):</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
    <span class="c"># hpl code:</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">numpy_array_type</span><span class="p">):</span>
        <span class="n">val</span> <span class="o">=</span> <span class="n">NumPyArray</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">Instance</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
    <span class="c"># end hpl code</span>
    <span class="k">elif</span> <span class="n">hasdict</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> <span class="ow">or</span> <span class="n">hasslots</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">Instance</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">Sequence</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">Mapping</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="nb">object</span><span class="p">):</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">Instance</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c"># print &quot;Couldn&#39;t classify&quot;, val, type(val)</span>
        <span class="n">thing</span> <span class="o">=</span> <span class="n">Simple</span><span class="p">(</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">thing</span>

</div>
<div class="viewcode-block" id="Snapframe"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Snapframe">[docs]</a><span class="k">class</span> <span class="nc">Snapframe</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the data structure that represents a frame&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tup</span><span class="p">):</span>
        <span class="n">frame</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">lineno</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">,</span> <span class="n">lines</span><span class="p">,</span> <span class="n">index</span> <span class="o">=</span> <span class="n">tup</span>
        <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">arg_names</span><span class="p">,</span>
         <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">,</span>
         <span class="bp">self</span><span class="o">.</span><span class="n">kwds</span><span class="p">,</span>
         <span class="nb">locals</span><span class="p">)</span> <span class="o">=</span> <span class="n">inspect</span><span class="o">.</span><span class="n">getargvalues</span><span class="p">(</span><span class="n">frame</span><span class="p">)</span>

        <span class="c"># make a copy of the dictionary of local vars</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">locals</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">locals</span><span class="p">)</span>

        <span class="c"># the function name for the top-most frame is __main__</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span> <span class="o">==</span> <span class="s">&#39;?&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">func</span> <span class="o">=</span> <span class="s">&#39;__main__&#39;</span>

<div class="viewcode-block" id="Snapframe.subtract"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Snapframe.subtract">[docs]</a>    <span class="k">def</span> <span class="nf">subtract</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;delete all the keys in other from self</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">locals</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">locals</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="k">print</span> <span class="n">key</span><span class="p">,</span> <span class="s">&quot;this shouldn&#39;t happen&quot;</span>
</div></div>
<div class="viewcode-block" id="Snapshot"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Snapshot">[docs]</a><span class="k">class</span> <span class="nc">Snapshot</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the data structure that represents a stack&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;convert from the format returned by inspect</span>
<span class="sd">        to a list of frames.  Drop the last three frames,</span>
<span class="sd">        which are the Lumpy functions object_diagram, make_stack,</span>
<span class="sd">        and Stack.__init__</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">st</span> <span class="o">=</span> <span class="n">inspect</span><span class="o">.</span><span class="n">stack</span><span class="p">()</span>
        <span class="n">frames</span> <span class="o">=</span> <span class="p">[</span><span class="n">Snapframe</span><span class="p">(</span><span class="n">tup</span><span class="p">)</span> <span class="k">for</span> <span class="n">tup</span> <span class="ow">in</span> <span class="n">st</span><span class="p">[</span><span class="mi">3</span><span class="p">:]]</span>
        <span class="n">frames</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">frames</span><span class="o">=</span><span class="n">frames</span>

<div class="viewcode-block" id="Snapshot.spew"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Snapshot.spew">[docs]</a>    <span class="k">def</span> <span class="nf">spew</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;print the frames in this snapshot&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">frame</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">frames</span><span class="p">:</span>
            <span class="k">print</span> <span class="n">frame</span><span class="o">.</span><span class="n">func</span><span class="p">,</span> <span class="n">frame</span>
</div>
<div class="viewcode-block" id="Snapshot.clean"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Snapshot.clean">[docs]</a>    <span class="k">def</span> <span class="nf">clean</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ref</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Remove all the variables in the reference stack from self&quot;&quot;&quot;</span>
        <span class="c"># NOTE: This currently only works on the top-most frame</span>
        <span class="n">f1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">frames</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">f2</span> <span class="o">=</span> <span class="n">ref</span><span class="o">.</span><span class="n">frames</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">f1</span><span class="o">.</span><span class="n">subtract</span><span class="p">(</span><span class="n">f2</span><span class="p">)</span>
                    
</div></div>
<div class="viewcode-block" id="Lumpy"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy">[docs]</a><span class="k">class</span> <span class="nc">Lumpy</span><span class="p">(</span><span class="n">Gui</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the Lumpy object represents the GUI window.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">pedantic</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;debug is passed to Gui.__init__; it makes the outlines</span>
<span class="sd">        of the frames visible.</span>
<span class="sd">        If pedantic is false, simple values are replicated, rather</span>
<span class="sd">        than, for example, having all references to 1 refer to the</span>
<span class="sd">        same int object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">Gui</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">debug</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">pedantic</span> <span class="o">=</span> <span class="n">pedantic</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">withdraw</span><span class="p">()</span>

        <span class="c"># initially there is no object diagram, no class diagram</span>
        <span class="c"># and no representation of the stack.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">od</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cd</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stack</span> <span class="o">=</span> <span class="bp">None</span>

        <span class="c"># instance_vars maps from classes to the instance vars</span>
        <span class="c"># that are drawn for that class; for opaque classes, it</span>
        <span class="c"># is an empty list.</span>

        <span class="c"># an instance of an opaque class is shown with a small empty box;</span>
        <span class="c"># the contents are not shown.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">instance_vars</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="c"># the following classes are opaque by default</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="n">Lumpy</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="n">Gui</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="nb">object</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">make_thing</span><span class="p">))</span>    <span class="c"># function</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="ne">Exception</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="nb">set</span><span class="p">)</span>

        <span class="c"># any object that belongs to a class in the Tkinter module</span>
        <span class="c"># is opaque</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_module</span><span class="p">(</span><span class="n">Tkinter</span><span class="p">)</span>

        <span class="c"># by default, class objects and module objects are opaque</span>
        <span class="n">classobjtype</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">Lumpy</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="n">classobjtype</span><span class="p">)</span>
        <span class="n">modtype</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">inspect</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="n">modtype</span><span class="p">)</span>

        <span class="c"># the __class__ of a new-style object is a type object.</span>
        <span class="c"># when type objects are drawn, show only the __name__</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="nb">type</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">make_reference</span><span class="p">()</span>

<div class="viewcode-block" id="Lumpy.restrict_class"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.restrict_class">[docs]</a>    <span class="k">def</span> <span class="nf">restrict_class</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">classobj</span><span class="p">,</span> <span class="nb">vars</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;restrict this class so that when it is drawn, only</span>
<span class="sd">        the given vars are shown</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">vars</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span> <span class="nb">vars</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">instance_vars</span><span class="p">[</span><span class="n">classobj</span><span class="p">]</span> <span class="o">=</span> <span class="nb">vars</span>
</div>
<div class="viewcode-block" id="Lumpy.opaque_class"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.opaque_class">[docs]</a>    <span class="k">def</span> <span class="nf">opaque_class</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">classobj</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;restrict this class to no variables&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">restrict_class</span><span class="p">(</span><span class="n">classobj</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Lumpy.is_opaque"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.is_opaque">[docs]</a>    <span class="k">def</span> <span class="nf">is_opaque</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">classobj</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;check whether this class is completely opaque</span>
<span class="sd">        (restricted to _no_ instance variables)&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">instance_vars</span><span class="p">[</span><span class="n">classobj</span><span class="p">]</span> <span class="o">==</span> <span class="p">[]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">False</span>
</div>
<div class="viewcode-block" id="Lumpy.transparent_class"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.transparent_class">[docs]</a>    <span class="k">def</span> <span class="nf">transparent_class</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">classobj</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;remove the given type or class from the dictionary, which</span>
<span class="sd">        means that it&#39;s attributes will be shown.  If it is not in</span>
<span class="sd">        the dictionary, raise an exception.&quot;&quot;&quot;</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">instance_vars</span><span class="p">[</span><span class="n">classobj</span><span class="p">]</span>
        </div>
<div class="viewcode-block" id="Lumpy.opaque_module"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.opaque_module">[docs]</a>    <span class="k">def</span> <span class="nf">opaque_module</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modobj</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;make all classes defined in this module opaque&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">var</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">modobj</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="n">Lumpy</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">opaque_class</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Lumpy.make_reference"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.make_reference">[docs]</a>    <span class="k">def</span> <span class="nf">make_reference</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;make a reference point by taking a snapshot of the current</span>
<span class="sd">        state.  Subsequent diagrams will be relative to this reference.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">make_reference2</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Lumpy.make_reference2"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.make_reference2">[docs]</a>    <span class="k">def</span> <span class="nf">make_reference2</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;this extra method call is here so that the reference</span>
<span class="sd">        and the snapshot we take later have the same number of</span>
<span class="sd">        frames on the stack.  UGH.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ref</span> <span class="o">=</span> <span class="n">Snapshot</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Lumpy.make_stack"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.make_stack">[docs]</a>    <span class="k">def</span> <span class="nf">make_stack</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;take a snapshot of the current state, subtract away the</span>
<span class="sd">        frames and variables that existed in the previous reference,</span>
<span class="sd">        then make a Stack.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">snapshot</span> <span class="o">=</span> <span class="n">Snapshot</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">snapshot</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ref</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">values</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">classes</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stack</span> <span class="o">=</span> <span class="n">Stack</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">snapshot</span><span class="p">)</span>
                </div>
<div class="viewcode-block" id="Lumpy.register"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.register">[docs]</a>    <span class="k">def</span> <span class="nf">register</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">thing</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;associate a value with the Thing that represents it,</span>
<span class="sd">        so that we can check later whether we have already created</span>
<span class="sd">        a Thing for a given value. &quot;&quot;&quot;</span>
        <span class="n">thing</span><span class="o">.</span><span class="n">lumpy</span> <span class="o">=</span> <span class="bp">self</span>
        <span class="n">thing</span><span class="o">.</span><span class="n">val</span> <span class="o">=</span> <span class="n">val</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">values</span><span class="p">[</span><span class="nb">id</span><span class="p">(</span><span class="n">val</span><span class="p">)]</span> <span class="o">=</span> <span class="n">thing</span>
    </div>
<div class="viewcode-block" id="Lumpy.lookup"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.lookup">[docs]</a>    <span class="k">def</span> <span class="nf">lookup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;check to see whether the given value is already represented</span>
<span class="sd">        by a Thing, and if so, return it.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">vid</span> <span class="o">=</span> <span class="nb">id</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">values</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">vid</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Lumpy.object_diagram"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.object_diagram">[docs]</a>    <span class="k">def</span> <span class="nf">object_diagram</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;create a new object diagram based on the current state.</span>
<span class="sd">        If an object is provided, draw the object.  Otherwise, draw</span>
<span class="sd">        the current run-time stack (relative to the last reference).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">obj</span><span class="p">:</span>
            <span class="n">thing</span> <span class="o">=</span> <span class="n">make_thing</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">make_stack</span><span class="p">()</span>
            <span class="n">thing</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span>

        <span class="c"># if there is already an Object Diagram, clear it; otherwise,</span>
        <span class="c"># create one</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">od</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">od</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">od</span> <span class="o">=</span> <span class="n">ObjectDiagram</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="c"># draw the object or stack, then the arrows</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">od</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">thing</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">od</span><span class="o">.</span><span class="n">draw_arrows</span><span class="p">()</span>

        <span class="c"># wait for the user</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Lumpy.get_class_list"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.get_class_list">[docs]</a>    <span class="k">def</span> <span class="nf">get_class_list</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the list of classes that should be drawn in</span>
<span class="sd">        a class diagram</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">t</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">cls</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">classes</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_opaque</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">classobj</span><span class="p">):</span>
                <span class="n">t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cls</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">cls</span><span class="o">.</span><span class="n">parents</span> <span class="ow">or</span> <span class="n">cls</span><span class="o">.</span><span class="n">childs</span><span class="p">:</span>
                <span class="n">t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cls</span><span class="p">)</span>
            
        <span class="k">return</span> <span class="n">t</span>
</div>
<div class="viewcode-block" id="Lumpy.class_diagram"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Lumpy.class_diagram">[docs]</a>    <span class="k">def</span> <span class="nf">class_diagram</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">classes</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;create a new object diagram based on the current state.</span>
<span class="sd">        If a list of classes is provided, only those classes are</span>
<span class="sd">        shown.  Otherwise, all classes that Lumpy know about are shown.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c"># if there is not already a snapshot, make one</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">make_stack</span><span class="p">()</span>

        <span class="c"># scan the the stack looking for has-a</span>
        <span class="c"># relationships (note that we can&#39;t do this until the</span>
        <span class="c"># stack is complete)</span>
        <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">values</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">Instance</span><span class="p">)</span> <span class="ow">and</span> <span class="n">val</span><span class="o">.</span><span class="n">cls</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">val</span><span class="o">.</span><span class="n">scan_bindings</span><span class="p">(</span><span class="n">val</span><span class="o">.</span><span class="n">cls</span><span class="p">)</span>
            
        <span class="c"># if there is already a class diagram, clear it; otherwise</span>
        <span class="c"># create one</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cd</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cd</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cd</span> <span class="o">=</span> <span class="n">ClassDiagram</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">classes</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">cd</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>

</div></div>
<div class="viewcode-block" id="Diagram"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Diagram">[docs]</a><span class="k">class</span> <span class="nc">Diagram</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;the parent class for ClassDiagram and ObjectDiagram.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span> <span class="o">=</span> <span class="n">lumpy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tl</span> <span class="o">=</span> <span class="n">lumpy</span><span class="o">.</span><span class="n">tl</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tl</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">title</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tl</span><span class="o">.</span><span class="n">geometry</span><span class="p">(</span><span class="s">&#39;+0+0&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tl</span><span class="o">.</span><span class="n">protocol</span><span class="p">(</span><span class="s">&quot;WM_DELETE_WINDOW&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setup</span><span class="p">()</span>

<div class="viewcode-block" id="Diagram.ca"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Diagram.ca">[docs]</a>    <span class="k">def</span> <span class="nf">ca</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;make a canvas for the diagram&quot;&quot;&quot;</span>
        <span class="n">underride</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="n">BOTH</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">sticky</span><span class="o">=</span><span class="n">N</span><span class="o">+</span><span class="n">S</span><span class="o">+</span><span class="n">E</span><span class="o">+</span><span class="n">W</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">widget</span><span class="p">(</span><span class="n">DiagCanvas</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="Diagram.setup"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Diagram.setup">[docs]</a>    <span class="k">def</span> <span class="nf">setup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;create the gui for the diagram&quot;&quot;&quot;</span>

        <span class="c"># push the frame for the toplevel window</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">pushfr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tl</span><span class="p">)</span>

        <span class="c"># the frame at the top contains buttons</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">fr</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">bg</span><span class="o">=</span><span class="s">&#39;white&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">bu</span><span class="p">(</span><span class="n">LEFT</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;Close&#39;</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">bu</span><span class="p">(</span><span class="n">LEFT</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;Print to file:&#39;</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">printfile</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">en</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">en</span><span class="p">(</span><span class="n">LEFT</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;lumpy.ps&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">endfr</span><span class="p">()</span>

        <span class="c"># the grid contains the canvas and scrollbars</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">gr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">ca_width</span> <span class="o">=</span> <span class="mi">1000</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ca_height</span> <span class="o">=</span> <span class="mi">500</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ca</span><span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ca_width</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ca_height</span><span class="p">,</span>
                              <span class="n">bg</span><span class="o">=</span><span class="s">&#39;white&#39;</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[])</span>

        <span class="n">yb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">sb</span><span class="p">(</span><span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">yview</span><span class="p">,</span> <span class="n">sticky</span><span class="o">=</span><span class="n">N</span><span class="o">+</span><span class="n">S</span><span class="p">)</span>
        <span class="n">xb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">sb</span><span class="p">(</span><span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">xview</span><span class="p">,</span> <span class="n">orient</span><span class="o">=</span><span class="n">HORIZONTAL</span><span class="p">,</span>
                         <span class="n">sticky</span><span class="o">=</span><span class="n">E</span><span class="o">+</span><span class="n">W</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">xscrollcommand</span><span class="o">=</span><span class="n">xb</span><span class="o">.</span><span class="n">set</span><span class="p">,</span> <span class="n">yscrollcommand</span><span class="o">=</span><span class="n">yb</span><span class="o">.</span><span class="n">set</span><span class="p">,</span>
                              <span class="n">scrollregion</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">800</span><span class="p">,</span> <span class="mi">800</span><span class="p">))</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">endgr</span><span class="p">()</span>

        <span class="c"># measure some sample letters to get the text height</span>
        <span class="c"># and set the scale factor for the canvas accordingly</span>
        <span class="n">bbox</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">measure</span><span class="p">([</span><span class="s">&#39;bdfhklgjpqy&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">unit</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">*</span> <span class="n">bbox</span><span class="o">.</span><span class="n">height</span><span class="p">()</span>
        <span class="n">transform</span> <span class="o">=</span> <span class="n">ScaleTransform</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">add_transform</span><span class="p">(</span><span class="n">transform</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">popfr</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Diagram.printfile"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Diagram.printfile">[docs]</a>    <span class="k">def</span> <span class="nf">printfile</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;dump the contents of the canvas to the filename in the</span>
<span class="sd">        filename entry.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">filename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">en</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
        <span class="n">bbox</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="n">ALL</span><span class="p">)</span>
        <span class="n">width</span><span class="o">=</span><span class="n">bbox</span><span class="o">.</span><span class="n">right</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">unit</span>
        <span class="n">height</span><span class="o">=</span><span class="n">bbox</span><span class="o">.</span><span class="n">bottom</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">unit</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">config</span><span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="n">height</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">config</span><span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ca_width</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ca_height</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Diagram.close"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Diagram.close">[docs]</a>    <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;close the window and exit&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tl</span><span class="o">.</span><span class="n">withdraw</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">quit</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Diagram.add_arrow"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Diagram.add_arrow">[docs]</a>    <span class="k">def</span> <span class="nf">add_arrow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">arrow</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;append a new arrow on the list&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">arrow</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Diagram.draw_arrows"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Diagram.draw_arrows">[docs]</a>    <span class="k">def</span> <span class="nf">draw_arrows</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw all the arrows on the list&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">arrow</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="p">:</span>
            <span class="n">arrow</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Diagram.update_arrows"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.Diagram.update_arrows">[docs]</a>    <span class="k">def</span> <span class="nf">update_arrows</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;update up to n arrows (or all of them is n==None)&quot;&quot;&quot;</span>
        <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">arrow</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="p">:</span>
            <span class="n">arrow</span><span class="o">.</span><span class="n">update</span><span class="p">()</span>
            <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="n">n</span> <span class="ow">and</span> <span class="n">i</span><span class="o">&gt;</span><span class="n">n</span><span class="p">:</span> <span class="k">break</span>

</div></div>
<div class="viewcode-block" id="ObjectDiagram"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ObjectDiagram">[docs]</a><span class="k">class</span> <span class="nc">ObjectDiagram</span><span class="p">(</span><span class="n">Diagram</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s">&#39;Object Diagram&#39;</span>
        <span class="n">Diagram</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">)</span>

<div class="viewcode-block" id="ObjectDiagram.draw"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ObjectDiagram.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">thing</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw the given thing&quot;&quot;&quot;</span>
        <span class="n">thing</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">Pos</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">]),</span> <span class="n">flip</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

        <span class="c"># configure the scroll region</span>
        <span class="n">bbox</span> <span class="o">=</span> <span class="n">Canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="p">,</span> <span class="n">ALL</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">scrollregion</span><span class="o">=</span><span class="n">bbox</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ObjectDiagram.clear"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ObjectDiagram.clear">[docs]</a>    <span class="k">def</span> <span class="nf">clear</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tl</span><span class="o">.</span><span class="n">deiconify</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">ALL</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ObjectDiagram.update_snapshot"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ObjectDiagram.update_snapshot">[docs]</a>    <span class="k">def</span> <span class="nf">update_snapshot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">snapshot</span><span class="p">):</span>
        <span class="k">pass</span>

</div></div>
<div class="viewcode-block" id="ClassDiagram"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ClassDiagram">[docs]</a><span class="k">class</span> <span class="nc">ClassDiagram</span><span class="p">(</span><span class="n">Diagram</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">,</span> <span class="n">classes</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s">&#39;Class Diagram&#39;</span>
        <span class="n">Diagram</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lumpy</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">classes</span> <span class="o">=</span> <span class="n">classes</span>

<div class="viewcode-block" id="ClassDiagram.draw"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ClassDiagram.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;draw the class diagram, including the classes in self.classes,</span>
<span class="sd">        or if there are none, then all the classes Lumpy has seen.&quot;&quot;&quot;</span>
        <span class="n">pos</span> <span class="o">=</span> <span class="n">Pos</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">classes</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">classes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="o">.</span><span class="n">get_class_list</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">classes</span> <span class="o">=</span> <span class="p">[</span><span class="n">make_thing</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">cls</span><span class="p">)</span> <span class="k">for</span> <span class="n">cls</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">classes</span><span class="p">]</span>

        <span class="c"># find the classes that have no parents, and find the</span>
        <span class="c"># height of each tree</span>
        <span class="n">roots</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">classes</span> <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">parents</span> <span class="o">==</span> <span class="p">[]]</span>
        <span class="k">for</span> <span class="n">root</span> <span class="ow">in</span> <span class="n">roots</span><span class="p">:</span>
            <span class="n">root</span><span class="o">.</span><span class="n">set_height</span><span class="p">()</span>

        <span class="c"># for all the leaf nodes, compute the distance to</span>
        <span class="c"># the parent</span>
        <span class="n">leafs</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">classes</span> <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">childs</span> <span class="o">==</span> <span class="p">[]]</span>
        <span class="k">for</span> <span class="n">leaf</span> <span class="ow">in</span> <span class="n">leafs</span><span class="p">:</span>
            <span class="n">leaf</span><span class="o">.</span><span class="n">set_depth</span><span class="p">()</span>

        <span class="c"># if we&#39;re drawing all the classes, start with the roots;</span>
        <span class="c"># otherwise draw the classes we were given.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">classes</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">drawn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">draw_classes</span><span class="p">(</span><span class="n">roots</span><span class="p">,</span> <span class="n">pos</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">drawn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">draw_classes</span><span class="p">(</span><span class="n">classes</span><span class="p">,</span> <span class="n">pos</span><span class="p">)</span>
            
        <span class="bp">self</span><span class="o">.</span><span class="n">draw_arrows</span><span class="p">()</span>

        <span class="c"># configure the scroll region</span>
        <span class="n">bbox</span> <span class="o">=</span> <span class="n">Canvas</span><span class="o">.</span><span class="n">bbox</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="p">,</span> <span class="n">ALL</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">scrollregion</span><span class="o">=</span><span class="n">bbox</span><span class="p">)</span>

        </div>
<div class="viewcode-block" id="ClassDiagram.draw_classes"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.ClassDiagram.draw_classes">[docs]</a>    <span class="k">def</span> <span class="nf">draw_classes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">classes</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="nb">tuple</span><span class="p">()):</span>
        <span class="sd">&quot;&quot;&quot;draw this list of classes and all their subclasses,</span>
<span class="sd">        starting at the given position.  Return a list of all</span>
<span class="sd">        classes drawn.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">alldrawn</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">classes</span><span class="p">:</span>
            <span class="n">drawn</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">cdc</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">tags</span><span class="p">)</span>
            <span class="n">alldrawn</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">drawn</span><span class="p">)</span>

            <span class="c"># change this so it finds the bottom-most bbox in drawn</span>
            <span class="n">bbox</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">cdc</span><span class="o">.</span><span class="n">bbox</span><span class="p">()</span>
            
            <span class="k">for</span> <span class="n">thing</span> <span class="ow">in</span> <span class="n">alldrawn</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">thing</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">c</span><span class="p">:</span>
                    <span class="c"># can&#39;t use bbox.union because it assumes that</span>
                    <span class="c"># the positive y direction is UP</span>
                    <span class="n">bbox</span> <span class="o">=</span> <span class="n">union</span><span class="p">(</span><span class="n">bbox</span><span class="p">,</span> <span class="n">thing</span><span class="o">.</span><span class="n">bbox</span><span class="p">())</span>
            
            <span class="n">p</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">bbox</span><span class="o">.</span><span class="n">bottom</span> <span class="o">+</span> <span class="mi">2</span>

        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">classes</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">refers</span><span class="p">:</span>
                <span class="n">a</span> <span class="o">=</span> <span class="n">ContainsArrow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lumpy</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">cdc</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">cdc</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">alldrawn</span>

</div></div>
<div class="viewcode-block" id="union"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.union">[docs]</a><span class="k">def</span> <span class="nf">union</span><span class="p">(</span><span class="n">one</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;return a new bbox that covers one and other,</span>
<span class="sd">    assuming that the positive y direction is DOWN&quot;&quot;&quot;</span>
    <span class="n">left</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">one</span><span class="o">.</span><span class="n">left</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">left</span><span class="p">)</span>
    <span class="n">right</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">one</span><span class="o">.</span><span class="n">right</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
    <span class="n">top</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">one</span><span class="o">.</span><span class="n">top</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">top</span><span class="p">)</span>
    <span class="n">bottom</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">one</span><span class="o">.</span><span class="n">bottom</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">bottom</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">BBox</span><span class="p">([[</span><span class="n">left</span><span class="p">,</span> <span class="n">top</span><span class="p">],</span> <span class="p">[</span><span class="n">right</span><span class="p">,</span> <span class="n">bottom</span><span class="p">]])</span>



<span class="c">###########################</span>
<span class="c"># test code below this line</span>
<span class="c">###########################</span>
</div>
<div class="viewcode-block" id="main"><a class="viewcode-back" href="../../Lumpy.html#scitools.Lumpy.main">[docs]</a><span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">Cell</span><span class="p">:</span>
        <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">car</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cdr</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">car</span> <span class="o">=</span> <span class="n">car</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cdr</span> <span class="o">=</span> <span class="n">cdr</span>

        <span class="k">def</span> <span class="nf">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">car</span><span class="p">)</span> <span class="o">^</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cdr</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">func_a</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
        <span class="n">t</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
        <span class="n">t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="n">z</span> <span class="o">=</span> <span class="il">1L</span>
        <span class="n">long_name</span> <span class="o">=</span> <span class="s">&#39;allen&#39;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>

        <span class="n">func_b</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">long_name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">func_b</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
        <span class="n">cell</span> <span class="o">=</span> <span class="n">Cell</span><span class="p">()</span>
        <span class="n">cell</span><span class="o">.</span><span class="n">car</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="n">cell</span><span class="o">.</span><span class="n">cdr</span> <span class="o">=</span> <span class="n">cell</span>
        <span class="n">func_c</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">func_c</span><span class="p">():</span>
        <span class="n">t</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">Cell</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">Cell</span><span class="p">())</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">d</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">=</span> <span class="mi">7</span>
        <span class="n">d</span><span class="p">[</span><span class="mi">7</span><span class="p">]</span> <span class="o">=</span> <span class="n">t</span>
        <span class="n">d</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">cdr</span>
        <span class="n">lumpy</span><span class="o">.</span><span class="n">object_diagram</span><span class="p">()</span>

    <span class="n">func_a</span><span class="p">(</span><span class="mi">17</span><span class="p">)</span>
</div>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">lumpy</span> <span class="o">=</span> <span class="n">Lumpy</span><span class="p">()</span>
    <span class="n">lumpy</span><span class="o">.</span><span class="n">make_reference</span><span class="p">()</span>
    <span class="n">main</span><span class="p">(</span><span class="o">*</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/scitools_logo.jpg" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SciTools 0.8.3 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, H. P. Langtangen, J. Ring, ++.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
    </div>
  </body>
</html>